{% extends "/based/based.html" %}
{% block content %}

<script type="text/javascript">


			function getParameterByName(name) {
				name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
				var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
					results = regex.exec(location.search);
				return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
			}

			function initOnReady() {
				var widget = window.tvWidget = new TradingView.widget({
					// debug: true, // uncomment this line to see Library errors and warnings in the console
					fullscreen: true,
					symbol: 'SC8888',
					interval: '1D',
					container_id: "tv_chart_container",
					timezone: "Asia/Shanghai",
					//	BEWARE: no trailing slash is expected in feed URL
					datafeed: new Datafeeds.UDFCompatibleDatafeed("{{'http://'+host+':8000'}}"),
					
					library_path: "static/js/charting_library/",
					locale: getParameterByName('lang') || "zh",

					disabled_features: ["volume_force_overlay"],
					enabled_features: ["study_templates","use_localstorage_for_settings","save_chart_properties_to_local_storage"],
					
					//disabled_features: ["use_localstorage_for_settings"],
					//enabled_features: ["study_templates","save_chart_properties_to_local_storage"],
					
					
					charts_storage_url: "{{'http://'+host+':8000'}}",
					//charts_storage_url: 'http://127.0.0.1:8000',
					charts_storage_api_version: "1.1",
					client_id: 'tradingview.com',
					user_id: '{{current_user.username}}',
					theme: getParameterByName('theme'),
					loading_screen: {backgroundColor: "#125236"},
					
					
					
					overrides: {
						
						"volume.volume.color.0": "#579e51",
						"volume.volume.color.1": "#d75442",
						"volume.volume.transparency": 70,
						
						"mainSeriesProperties.candleStyle.upColor": "#d75442",
						"mainSeriesProperties.candleStyle.downColor": "#579e51",
						"mainSeriesProperties.candleStyle.borderColor": "#225437",
						"mainSeriesProperties.candleStyle.borderUpColor": "#d75442",
						"mainSeriesProperties.candleStyle.borderDownColor": "#378658",
						"mainSeriesProperties.candleStyle.wickUpColor": 'rgba( 115, 115, 117, 1)',
						"mainSeriesProperties.candleStyle.wickDownColor": 'rgba( 115, 115, 117, 1)',
						"mainSeriesProperties.haStyle.upColor":  "#d75442",
						"mainSeriesProperties.haStyle.downColor":"#6ba583",
						
						"linetoolhorzline.linecolor": 'rgba( 0, 0, 0, 1)',
						"linetoolhorzline.linestyle": '3',
						"linetooltrendbasedfibextension.fillBackground":false,
						"linetooltrendbasedfibextension.coeffsAsPercents":true,
						

						"timezone": "Asia/Shanghai",
					},
					debug: false,
					
					
				    custom_indicators_getter: function(PineJS) {
				         return Promise.resolve([
			             // *** 您的指标对象，通过模板创建 ***
			             
			             {% if 'OI' in addWindow %}
			             
			        	 {
						    name: "OI",
						    metainfo: {
						        "_metainfoVersion": 40,
						        "id": "OI@tv-basicstudies-1",
						        "scriptIdPart": "",
						        "name": "OI",
						        "description": "OI",
						        "shortDescription": "openInterest",
						
						        'is_hidden_study': true,
					        	'is_price_study': false,
					        	'isCustomIndicator': true,
						
						        "plots": [{"id": "plot_0", "type": "line"}],
						        "defaults": {
						            "styles": {
						                "plot_0": {
						                    "linestyle": 0,
						                    "visible": true,
						
						                    // 使线条变细
						                    "linewidth": 3,
						
						                    // 绘制类型为线性图
						                    "plottype": 2,
						
						                    // 显示价格线
						                    "trackPrice": true,
						
						                    "transparency": 50,
						
						                    // 为图线设置深红色。
						                    "color": "#880000"
						                }
						            },
						
						            // 精度为小数点后一位数，如777.7
						            "precision": 1,
						
						            "inputs": {}
						        },
						        "styles": {
						            "plot_0": {
						                // 输出名字在样式窗口显示
						                "title": "OI value",
						                "histogramBase": 0,
						            }
						        },
						        "inputs": [],
						    },
						
						    constructor: function() {
						        this.init = function(context, inputCallback) {
						            this._context = context;
						            this._input = inputCallback;
						
						            //var symbol = "#OI";
						            var symbol = PineJS.Std.ticker(this._context).split('"')[1]+'_OI';
						            this._context.new_sym(symbol, PineJS.Std.period(this._context), PineJS.Std.period(this._context));
						        };
						
						        this.main = function(context, inputCallback) {
						            this._context = context;
						            this._input = inputCallback;
						
						            this._context.select_sym(1);
						
						            var v = PineJS.Std.close(this._context);
						            return [v];
						        }
						    }
						},
						
				    	{% endif %}
						
						{% if 'BT' in addWindow %}
						{
						    name: "BT",
						    metainfo: {
						        "_metainfoVersion": 40,
						        "id": "BT@tv-basicstudies-2",
						        "scriptIdPart": "",
						        "name": "BT",
						        "description": "BT",
						        "shortDescription": "回测",
						
						        'is_hidden_study': true,
					        	'is_price_study': false,
					        	'isCustomIndicator': true,
						
						        "plots": [{"id": "plot_0", "type": "line"}],
						        "defaults": {
						            "styles": {
						                "plot_0": {
						                    "linestyle": 0,
						                    "visible": true,
						
						                    // 使线条变细
						                    "linewidth": 3,
						
						                    // 绘制类型为线性图
						                    "plottype": 2,
						
						                    // 显示价格线
						                    "trackPrice": false,
						
						                    "transparency": 50,
						
						                    // 为图线设置深红色。
						                    "color": "#660088"
						                }
						            },
						
						            // 精度为小数点后一位数，如777.7
						            "precision": 1,
						
						            "inputs": {}
						        },
						        "styles": {
						            "plot_0": {
						                // 输出名字在样式窗口显示
						                "title": "BT value",
						                "histogramBase": 0,
						            }
						        },
						        "inputs": [],
						    },
						
						    constructor: function() {
						        this.init = function(context, inputCallback) {
						            this._context = context;
						            this._input = inputCallback;
						
						            //var symbol = "#OI";
						            var symbol = PineJS.Std.ticker(this._context).split('"')[1]+'_BT';
						            this._context.new_sym(symbol, PineJS.Std.period(this._context), PineJS.Std.period(this._context));
						        };
						
						        this.main = function(context, inputCallback) {
						            this._context = context;
						            this._input = inputCallback;
						
						            this._context.select_sym(1);
						
						            var v = PineJS.Std.close(this._context);
						            return [v];
						        }
						    }
						}
						{% endif %}
     
				             
				             
				         ]
				         );
				     },
				});
				
				{% if 'OI' in addWindow %}
				widget.onChartReady(function() {
				     widget.chart().createStudy('OI', false, true);
				 });
				{% endif %}
				
				{% if 'BT' in addWindow %}
			   widget.onChartReady(function() {
				     widget.chart().createStudy('BT', false, true);
				 });
				{% endif %}

				
				
				/*
				
				widget.headerReady().then(function() {
				    var button_alert = widget.createButton();
				    button_alert.setAttribute('title', 'Alert');
				    button_alert.addEventListener('click', function openWin(){
				    	myWindow=window.open('','','width=300,height=500');
				    	myWindow.document.write('<div id="alert" style="font-size: 12px;"></div>');
				    	myWindow.document.getElementById("alert").innerHTML='{{alert_tbl|safe}}';
				    	//myWindow.document.getElementById("alert").style.fontSize="12";
				    	myWindow.focus();});
				    button_alert.textContent = 'Alert';
				    
				    var button_top_att = widget.createButton();
				    button_top_att.setAttribute('title', 'Top_att+-');
				    button_top_att.addEventListener('click', function openWin(){
				    	myWindow=window.open('','','width=300,height=500');
				    	myWindow.document.write('<div id="top_att" style="font-size: 12px;"></div>');
				    	myWindow.document.getElementById("top_att").innerHTML='{{top_att_tbl|safe}}';
				    	//myWindow.document.getElementById("alert").style.fontSize="12";
				    	myWindow.focus();});
				    button_top_att.textContent = 'Top_att+-';
				    
				    var button_top_att = widget.createButton();
				    button_top_att.setAttribute('title', 'Top_cp+-');
				    button_top_att.addEventListener('click', function openWin(){
				    	myWindow=window.open('','','width=300,height=500');
				    	myWindow.document.write('<div id="Top_cp" style="font-size: 12px;"></div>');
				    	myWindow.document.getElementById("Top_cp").innerHTML='{{top_cp_tbl|safe}}';
				    	//myWindow.document.getElementById("alert").style.fontSize="12";
				    	myWindow.focus();});
				    button_top_att.textContent = 'Top_cp+-';
				});
				
				*/
			};

			window.addEventListener('DOMContentLoaded', initOnReady, false);
		</script>

	


	<div id="user" style="text-align: right;">
    <span style="font-size: 14px;"><br>用户 [ {{current_user.username}} ] 已登录 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; </span>
    </div>

	 <div id="tv_chart_container"></div>
	<script src="{{url_for('static',filename='js/charting_library/charting_library.standalone.js')}}"></script>
	<script src="{{url_for('static',filename='js/datafeeds/udf/dist/polyfills.js')}}"></script>
	<script src="{{url_for('static',filename='js/datafeeds/udf/dist/bundle.js')}}"></script>

{% endblock %}